package com.region.http.client.process;

import com.region.http.client.core.ClientProxyHandler;
import com.region.http.client.core.ProtectorMechanism;
import com.region.http.client.exception.ResponseErrorException;
import com.region.http.client.model.RequestMeta;
import com.region.http.client.model.RequestParameter;
import com.region.http.client.model.ResponseData;
import com.region.http.client.request.HttpExecutor;
import com.region.http.client.resolver.parameter.ParameterResolver;
import com.region.http.client.resolver.result.ResultResolver;

import java.util.List;

/**
 * @author liujieyu
 * @date 2023/7/8 21:04
 * @description
 */
public class SingleExecutorProcess extends AbstractExecutorProcess {

    public SingleExecutorProcess(List<ParameterResolver> parameterResolvers, List<ResultResolver> resultResolvers,
                                 ClientProxyHandler handler, ProtectorMechanism protectorMechanism) {
        super(parameterResolvers, resultResolvers, handler, protectorMechanism);
    }

    @Override
    public ResponseData execute(RequestMeta requestMeta, HttpExecutor executor, RequestParameter parameter) {
        try {
            return executor.execute(wrappingUrl(requestMeta.getUrl(), requestMeta, parameter.getPrimitiveArgs()),
                    requestMeta.getRequestAnnotationConfig(), parameter);
        } catch (Throwable e) {
            throw new ResponseErrorException(e);
        }
    }

}
